package mapreduce;

import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;


/**
 * @author Guimin Lin
 * @date Feb 1, 2011
 */
public class WordReducer extends MapReduceBase implements Reducer<Text, LongWritable, Text, LongWritable> {
	@Override
	public void reduce(Text key, Iterator<LongWritable> values,
			OutputCollector<Text, LongWritable> output, Reporter arg3)
			throws IOException {
		int sum = 0;
		while (values.hasNext()) {
			sum += values.next().get();//sum up all the occurence
		}
		output.collect(key, new LongWritable(sum));
	}
}
